<!DOCTYPE html>
<html>
	<head>
		<title>选择商业问题</title>
		<meta http-equiv="content-type" content="textml; charset=utf-8" />
		<meta name="description" content="__DESCRIPTION__">
		<meta name="keywords" content="__KEYWORDS__">
		<link href="__CSS__/common.css" rel="stylesheet" type="text/css" />
		<link href="__CSS__/Version4Master.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" async="" src="__JS__/ga.js"></script>
		<script src="__JS__/jquery-1.4.1.js" type="text/javascript"></script>
		<link href="__CSS__/setting.css" rel="stylesheet" type="text/css" />
		<link href="__CSS__/account.css" rel="stylesheet" type="text/css" />
		<link href="__CSS__/addproject.css" rel="stylesheet" type="text/css" />
		<link href="__CSS__/thickbox.css" rel="stylesheet" type="text/css" />
		<script src="__JS__/thickbox-compressed.js" type="text/javascript"></script>
		<script src="__JS__/tiny_mce.js" type="text/javascript"></script>
		<script src="__JS__/project.js" type="text/javascript"></script>
		<link href="__CSS__/validator.css" rel="stylesheet" type="text/css" />
		<script src="__JS__/formValidator.js" type="text/javascript"></script>
		<script src="__JS__/formValidatorRegex.js" type="text/javascript"></script>
		<script type="text/javascript">
		
		
        /*------设置提交类型-----
        ------0:未选择竞赛项目的-----
        ------1:选择给定的-----
        ------2:自拟问题------
        ------3:拓展企业------
        ------4:创业项目--------*/
        var submittype = 0;
        /*-----------获取竞赛项目--------*/
        function GetProblems(id) {
            if (id == -2) {
                $("#problems").children().remove();
                $("#problems").append("<option value=\"-1\">——请选择——</option>");
				$("#problems")[0].disabled = "";
                $(".edit_item").hide();
                $(".ex").show();
                submittype = 0;
            } else if (id == -1) { //如果是自行拓展企业
                $(".edit_item").hide();
                $(".en").show();
                $(".ex").show();
                $("#problems").children().remove();
                $("#problems").append("<option value=\"-1\">自拟竞赛项目</option>");
                $("#problems")[0].disabled = "disabled";
                submittype = 3;
            } else {
                $("#problems")[0].disabled = "";
                $(".edit_item").hide();
                $(".ex").show();
				var id=$("#enterprises option:selected").val();
                $.ajax({
                    url: '__URL__/returnProlems',
                    type: 'post',
                    data: {eId: id },
                    dataType: 'json',
                    success: function (data) {
                        $("#problems").children().remove();
                        var num = data.data.length;  //标识企业的竞赛项目数
                        if (num == 0) {
                            SelfProblem();
                        } else {
                            $("#problems").prepend("<option value=\"-2\">——请选择——</option>");
                            $.each(data.data, function (i, item) {
                                $("#problems").append("<option value=\"" + item['Id'] + "\">" + item['Title'] + "</option>");
                            });
                            submittype = 1;
                        }
                        $("#problems").append("<option value=\"-1\">自拟竞赛项目</option>");
                    },
                    error: function () { alert(id); }
                });
            }
        }
        /*--------页面加载完成--------*/
        $(document).ready(function () {
            r1();
            $("#r1").click(function () { r1(); });
            $("#r2").click(function () {
                $(".edit_item").hide();
                $(".create").show();
                submittype = 4;
                $("#viewall")[0].style.display = "none";
                ClearForm();
            });
            InitEnterprises();
            //GetProblems(2);
            $("#problems").prepend("<option value=\"-2\">——请选择——</option>");
            $("#enterprises").change(function () {
				//alert(parseInt($(this).val()));
                GetProblems(parseInt($(this).val()));
                ClearForm();
				
            });
            $("#problems").change(function () {
                    ClearForm();
                if (parseInt($(this).val()) == -1) {
                    SelfProblem();
                } else {
                    $(".create").hide();
                    $(".ex").show();
                    submittype = 1;
                }
            });
            //$.formValidator.initConfig({ formid: "aspnetForm", onerror: function (msg) { alert(msg) }, onsuccess: function () { return true; } });
			
        });
        /*----初始化界面-----*/
        function r1() {
            $(".edit_item").hide();
            $(".ex").show();
            $("#viewall").show();
            submittype = 0;
            /*-------第二次加载方法时须判断之前的操作-------*/
            if (parseInt($("#problems option:selected").val()) == -1) {
                $(".create").show();
                submittype = 2;
                ClearForm();
            }
            if (parseInt($("#enterprises option:selected").val()) == -1) {
                submittype = 3;
                ClearForm();
            }
        }
        /*-----清空网页上的输入框-----*/
        function ClearForm()
        {
        $("#txtEnName").val(""); //企业名称
        $("#txtContactor").val("");//联系人姓名
        $("#txtJob").val(""); //职务
        $("#txtPhoneNumber").val(""); //联系电话
        $("#txtProblemTitle").val(""); //竞赛项目的名称
        $("#txtProblemGoal").val(""); //竞赛项目目标
        $("#txtProblemDescription").val("");//竞赛项目描述
        }
        /*--------------检验自拟竞赛项目输入------*/
        function CheckSelf()
        {
            if ($("#txtProblemTitle").val()=="") {
             alert("竞赛项目不能为空");
             $("#txtProblemTitle").focus();
             return false ;
             }
             if ($("#txtProblemGoal").val()=="") {
                alert("竞赛项目目标不能为空！");
                $("#txtProblemGoal").focus();
                return false ;
            }
            if ($("#txtProblemDescription").val()=="") {
                alert("竞赛项目描述不能为空！");
                $("#txtProblemDescription").focus();
                return false;
            }
            return true;
        }
        function CheckExtend()
        {
            var enName=$("#txtEnName"); //企业名称
            var contactor=$("#txtContactor"); //联系人姓名
            var job=$("#txtJob"); //职务
            var tele=$("#txtPhoneNumber"); //联系电话
            var tele1=$("#txtPhoneNumber1");
            if (enName.val()=="") {
                alert("企业名称不能为空！");
                enName.focus();
                return false;
            }
            if (contactor.val()=="") {
                alert("联系人姓名不能为空！");
                contactor.focus();
                return false;
            }
            if (job.val()=="") {
                alert("职务不能为空！");
                job.focus();
                return false;
            }
            if (tele.val()=="") {
                alert("区号不能为空！")
                tele.focus();
                return false;
            }
            if (tele1.val()=="") {
                alert("电话号码不能为空");
                tele1.focus();
                return false;
            }
            return CheckSelf();
        }
        /*-----初始化企业列表------*/
        function InitEnterprises() {
            $.ajax({
                url: '__URL__/returnEnterprises',
                type: 'post',
                data: {provinceid:5},
                dataType: 'json',
                success: function (data) {
                    $("#enterprises").append("<option value=\"-2\">——请选择——</option>");
                    $.each(data.data, function (i, item) {
                        $("#enterprises").append("<option value=\"" + item['Id'] + "\">" + item['Name'] + "</option>");
                    })
                    $("#enterprises").append("<option value=\"-1\">自行拓展企业</option>");

                },
                error: function () { alert("error"); }
            });
        }
        /*---------自拟竞赛项目-------*/
        function SelfProblem() {
            $(".edit_item").hide();
            $(".ex").show();
            $(".create").show();
            submittype = 2;
        }
        /*------------提交竞赛项目并重定向-------------------*/
        function submitSelectAndRedirect(url) {
            SubmitSelect();
            if (!url) {
                window.location = "__APP__/";
            }
            else {
                window.location = url;
            }
        }
        /*------------提交竞赛项目并重定向-------------------*/

        /*-----------------提交竞赛项目-----------------------------*/
		/*------设置提交类型-----
        ------0:未选择竞赛项目的-----
        ------1:选择给定的-----
        ------2:自拟问题------
        ------3:拓展企业------
        ------4:创业项目--------*/
        function SubmitSelect() {
            if (submittype == 0) {
                alert("请选择竞赛项目！");
                $("#enterprises").focus();
            }else if (submittype == 1) {
				if ($("#problems option:selected").val()=="-2") {
					alert("请选择竞赛项目！");
					$("#problems").focus();
				}else{
					var tid={$Think.get.id};
					if(confirm('确认提交吗？'))
					$.ajax({
						url: '__URL__/SelectExist',
						type: 'post',
						data: {problemId:parseInt($("#problems option:selected").val()),enterpriseId:parseInt($("#enterprises option:selected").val()),teamId:tid},
						dataType: 'json',
						success: function (data) {
							if (data.info == "选择商业问题失败！") {
								alert(data.info);
							} else {
								window.location.href='__URL__/AdviseAddProject/id/'+tid;
							}
						},
						error: function () { alert("错误"); }
					});
					
				}
			}else if (submittype == 2) {
			   if (CheckSelf()) {
					var tid={$Think.get.id};
					if(confirm('确认提交吗？'))
					$.ajax({
						url: '__URL__/SelectSelfProblem',
						type: 'post',
						data: {enterpriseId:parseInt($("#enterprises option:selected").val()),teamId:tid ,problemTitle:$("#txtProblemTitle").val(),goal:$("#txtProblemGoal").val(),description: $("#txtProblemDescription").val()},
						dataType: 'json',
						success: function (data) {
							if (data.info == "选择商业问题失败！") {
								alert(data.info);
							} else {
								window.location.href='__URL__/AdviseAddProject/id/'+tid;
							}
						},
						error: function () { alert("错误"); }
					});
				}
			}else if (submittype == 3) {
			   if(CheckExtend()){
					var tid={$Think.get.id};
					if(confirm('确认提交吗？'))
					$.ajax({
						url: '__URL__/SelectExpandEnterprise',
						type: 'post',
						data: {teamId:tid,enterpriseName:$("#txtEnName").val(),contactor:$("#txtContactor").val(),phoneNumber:$("#txtPhoneNumber").val()+'-'+$("#txtPhoneNumber1").val(),problemTitle:$("#txtProblemTitle").val(),goal:$("#txtProblemGoal").val(),description: $("#txtProblemDescription").val(),job:$("#txtJob").val()},
						dataType: 'json',
						success: function (data) {
							if (data.info == "选择商业问题失败！") {
								alert(data.info);
							} else {
								window.location.href='__URL__/AdviseAddProject/id/'+tid;
							}
						},
						error: function () { alert("错误"); }
					});
				}
			}else  if (submittype == 4) {
					if (CheckSelf()) {
					var tid={$Think.get.id};
					if(confirm('确认提交吗？'))
					$.ajax({
						url: '__URL__/SelectCreate',
						type: 'post',
						data: {teamId: tid ,problemTitle: $("#txtProblemTitle").val() ,goal:  $("#txtProblemGoal").val() ,description: $("#txtProblemDescription").val()},
						dataType: 'json',
						success: function (data) {
							if (data.info == "选择商业问题失败！") {
								alert(data.info);
							} else {
								window.location.href='__URL__/AdviseAddProject/id/'+tid;
							}
						},
						error: function () { alert("错误"); }
						});
					}
				}
        }
		
    </script>
	</head>
	<body>
		<form name="aspnetForm" method="post" action="__URL__/sureMatch" id="aspnetForm">
			<script type="text/javascript">
			//<![CDATA[
			var theForm = document.forms['aspnetForm'];
			if (!theForm) {
				theForm = document.aspnetForm;
			}
			function __doPostBack(eventTarget, eventArgument) {
				if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
					theForm.__EVENTTARGET.value = eventTarget;
					theForm.__EVENTARGUMENT.value = eventArgument;
					theForm.submit();
				}
			}
			//]]>
			</script>
			<div id="container">
				<include file="./Match/Tpl/Include/header.html" />
				<div class="clear"></div>
				<div id="container_content">
					<div class="topic_nav_block_wrapper">
						<ul class="topic_nav_block">

							<li><a  class="current_nav" href="__URL__/showMatch/id/{$Think.get.id}">商业实践项目</a> </li>
							<empty name="res">
							<li><a onclick="alert('请选择商业实践项目');" href="javascript:void(0)">方案展示</a></li>
							<li><a onclick="alert('请选择商业实践项目');" href="javascript:void(0)">参赛主题</a> </li>
							<li><a onclick="alert('请选择商业实践项目');" href="javascript:void(0)">详细方案</a> </li>
							<li><a onclick="alert('请选择商业实践项目');" href="javascript:void(0)">实践作品展示</a> </li>
							<else />
								<empty name="res.Name">
									<li><a href="__URL__/modProject/id/{$Think.get.id}">方案展示</a></li>
									<li><a onclick="alert('请先填写方案展示');" href="javascript:void(0)">参赛主题</a> </li>
									<li><a onclick="alert('请先填写方案展示');" href="javascript:void(0)">详细方案</a> </li>
									<li><a onclick="alert('请先填写方案展示');" href="javascript:void(0)">实践作品展示</a> </li>
								<else />
									<li><a href="__URL__/modProject/id/{$Think.get.id}">方案展示</a></li>
									<li><a href="__URL__/modTheme/id/{$Think.get.id}">参赛主题</a> </li>
									<li><a href="__URL__/uploadProjectFile/id/{$Think.get.id}">详细方案</a> </li>
									<li><a href="__URL__/addWorks/id/{$Think.get.id}">实践作品展示</a> </li>
								</empty>
							</empty>
							<li style=" float:right;"><a class="teamnav" href="__APP__/Team/Home/index/id/{$Think.get.id}">返回团队主页</a></li>
						</ul>
						<div class="clear"></div>
					</div>
					<empty name="res">
					<div style="display: block;" class="edit_item create ex">
						<label class="legend">项目类型：</label>
						<input value="" checked="checked" name="cat" id="r1" type="radio" /><label for="r1">企业项目</label>
						<input value="" name="cat" id="r2" type="radio" /><label for="r2">创业项目</label>
						<a href="###" id="viewall" style="text-decoration: underline;">浏览全部竞赛项目</a>
					</div>
					<div style="display: block;" class="edit_item ex">
						<label class="legend">选择出题企业：</label>
						<select id="enterprises">
						
						</select>
					</div>
					<div style="display: block;" class="edit_item ex">
						<label class="legend">选择选择问题：</label>
						<select id="problems">
						</select>
					</div>
					<else />
					<h3>你已经选择了商业实践项目</h3>
					<div style="display: block;" class="edit_item create ex">
						<label class="legend">项目类型：</label>
						<label for="r1">{$res.ProjectType}</label>
					</div>
					<div style="display: block;" class="edit_item ex">
						<label class="legend">选择出题企业：</label>
						<label for="r1">{$ename.Name|default='自主创业'}</label>
					</div>
					<div style="display: block;" class="edit_item ex">
						<label class="legend">选择选择问题：</label>
						<label for="r1">{$pname.Title}</label>
					</div>
					</empty>
					<div style="display: none;" class="edit_item en">
						<label class="legend">企业名称：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input id="txtEnName" class="inupt_text" maxlength="50" style="width:250px;" type="text" />
						<label class="onShow">
							必填项，最长为50个字符
						</label>
					</div>
					<div style="display: none;" class="edit_item en">
						<label class="legend">
							联系人姓名：&nbsp;&nbsp;&nbsp;</label>
						<input id="txtContactor" maxlength="4" class="inupt_text" style="width: 150px; " type="text">
						<label class="onShow">
						必填项，最长为4个字符</label>
						<label class="legend" style=" margin-left:50px;">
							职务：</label>
						<input id="txtJob" maxlength="10" class="inupt_text" style="width: 200px;" type="text">
						<label class="onShow">
						 必填项，最多10个字符
						</label>
					</div>
					<div style="display: none;" class="edit_item en">
						<label class="legend">
							联系电话：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input id="txtPhoneNumber" class="inupt_text" style="width:45px;" type="text"><label class="legend">—</label>
						<input id="txtPhoneNumber1" class="inupt_text" style="width:100px" type="text"><label class="onShow">必填项，示例：010-3785888</label>
					</div>
					<div style="display: block;" class="edit_item problemexpand create en">
						<label class="legend">
							竞赛项目名称：</label>
						<input id="txtProblemTitle" class="inupt_text">
						<label class="onShow">
							必填项，最多为50个字符
						</label>
					</div>
					<div style="display: block;" class="edit_item problemexpand create en">
						<label class="legend">
							竞赛项目目标：</label>
						<textarea rows="6" cols="8" class="text_area" id="txtProblemGoal"></textarea>
						<label class="onShow">
							必填项，最多为400字符
						</label>
					</div>
					<div style="display: block;" class="edit_item problemexpand create en">
						<label class="legend">
							竞赛项目描述：</label>
						<textarea rows="6" cols="8" class="text_area" id="txtProblemDescription"></textarea>
						<label class="onShow">
							必填项，最多为400字符
						</label>
					</div>
					<empty name="res">
					<div id="operate">
						<input onclick="SubmitSelect();" class="input-submit" value="选择此商业问题" type="button" />
						<input class="input-button gray" style=" margin-left:25px;" value="取消" type="button" />
					</div>
					</empty>
				</div>
				<div class="clear"></div>
				<include file="./Match/Tpl/Include/footer.html" />
			</div>

		</form>
	</body>
</html>